package com.xuecheng.comment.controller;


import com.xuecheng.api.comment.CommentAPI;
import com.xuecheng.api.comment.model.dto.CommentDTO;
import com.xuecheng.api.comment.model.qo.CommentConditionModel;
import com.xuecheng.api.comment.model.vo.CommentStatisticsVo;
import com.xuecheng.comment.service.CommentService;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 课程评论功能
 */
@Slf4j
@RestController
public class CommentController implements CommentAPI {

    @Autowired
    private CommentService commentService;

    /*
     * 评论列表--微服务
     * */
    @PostMapping("/l/list")
    public RestResponse<PageVO<CommentDTO>> list(PageRequestParams params, @Valid @RequestBody CommentConditionModel commentModel, Boolean company) {

        return commentService.list(params, commentModel, company);
    }

    @PostMapping("course-comment")
    public RestResponse<CommentDTO> comment(@Valid @RequestBody CommentDTO commentDTO) {
        return commentService.addComment(commentDTO);
    }


    // TODO：评论点赞待完成
    @PostMapping(path = "course-comment/praise/{commentId}")
    public RestResponse<CommentDTO> praise(@PathVariable Long commentId) {
        RestResponse<CommentDTO> dtoRestResponse = commentService.praise(commentId);
        return dtoRestResponse;
    }


    @DeleteMapping("{commentId}")
    public RestResponse<CommentDTO> delComment(@PathVariable Long commentId) {
        RestResponse<CommentDTO> dtoRestResponse = commentService.delComment(commentId);
        return dtoRestResponse;
    }

    @DeleteMapping("batch-del/{commentIds}")
    public RestResponse<Boolean> batchDelComment(@PathVariable List<Long> commentIds) {

        return commentService.batchDelComment(commentIds);

    }

    /*
     * 统计
     * */
    @Override
    @GetMapping("l/course-comment/course-statistics/{coursePubId}")
    public RestResponse<CommentStatisticsVo> getStatistics(@PathVariable Long coursePubId) {

        return commentService.getCommentStatistics(coursePubId);
    }


    @PostMapping("l/comment/{commentId}")
    public RestResponse<CommentDTO> getCommentById(@PathVariable Long commentId) {

        return commentService.getCommentById(commentId);
    }

}

